/*
 * @Author: your name
 * @Date: 2021-09-18 09:14:27
 * @LastEditTime: 2021-09-18 09:55:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \express-learn\utils\dbconfig.js
 */
const mysql = require('mysql');
module.exports = {
    config: {
        host: 'localhost',
        user: 'root',
        port: '3306',
        password: 'zhao010106',
        // password: 'wmq12138',
        database: 'nodeapp'
    },
    //连接数据库
    sqlConnection(sql, sqlArr, callback) {
        let pool = mysql.createPool(this.config);
        pool.getConnection((err, conn) => {
            if (err) {
                console.log('数据库连接失败');
                return;
            }
            // 事件驱动回调
            conn.query(sql, sqlArr, callback);
            //关闭连接
            conn.release();
        });
    }
}
